package com.lzy.cloud.sms.controller;

import com.lzy.cloud.sms.dtos.TmpSmsSendDto;
import com.lzy.cloud.sms.request.TmpSmsSendRequest;
import com.lzy.cloud.sms.response.TmpSmsSendResponse;
import com.lzy.cloud.sms.service.TmpSmsSendService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/tmp/sms/send")
@Slf4j
public class TmpSmsSendController {

    @Autowired
    TmpSmsSendService tmpSmsSendService;

    /**
     * 新增待发送短信
     *
     * @param tmpSmsSendRequest
     * @return
     */
    @RequestMapping(value = "/add",method =RequestMethod.POST)
    public Result add(TmpSmsSendRequest tmpSmsSendRequest) {
        Ensure.that(tmpSmsSendRequest).isNotNull("00000010");
        Boolean ok = tmpSmsSendService.insert(DozerUtils.map(tmpSmsSendRequest,TmpSmsSendDto.class));
        return new Result(ok);
    }

    /**
     * 根据条件更新待发送短信
     *
     * @param tmpSmsSendRequest
     * @return
     */
    @RequestMapping(value = "/update",method =RequestMethod.POST)
    public Result update(TmpSmsSendRequest tmpSmsSendRequest) {
        Ensure.that(tmpSmsSendRequest).isNotNull("00000010");
        Boolean ok = tmpSmsSendService.updateStatus(DozerUtils.map(tmpSmsSendRequest,TmpSmsSendDto.class));
        return new Result(ok);
    }

    /**
     * 查询待发送短信/推送列表
     *
     * @param tmpSmsSendRequest
     * @return
     */
    @RequestMapping(value = "/list",method =RequestMethod.GET)
    public Result selectList(TmpSmsSendRequest tmpSmsSendRequest) {
        List<TmpSmsSendDto> tmpSmsSendDtoList = tmpSmsSendService.selectList(DozerUtils.map(tmpSmsSendRequest,TmpSmsSendDto.class));
        return new Result(DozerUtils.maps(tmpSmsSendDtoList,TmpSmsSendResponse.class));
    }
}
